package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.admin.pojos.AdminUserPojo;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.AdminUserWmMapper;
import com.heima.wemedia.service.AdminUserWmService;
import io.micrometer.core.instrument.binder.BaseUnits;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
@Slf4j
public class AdminUserWmServiceImpl extends ServiceImpl<AdminUserWmMapper, WmUser> implements AdminUserWmService {
    /**
     * 远程添加用户数据
     *
     * @param user
     * @return
     */
    @Override
    public ResponseResult updateStatus(ApUser user) {
        try {

            WmUser wmUser = new WmUser();
            wmUser.setApUserId(user.getId());
            wmUser.setName(user.getName());
            wmUser.setPassword(user.getPassword());
            wmUser.setStatus(9);
            wmUser.setSalt(user.getSalt());
            wmUser.setImage(user.getImage());
            wmUser.setCreatedTime(new Date());
            save(wmUser);
        } catch (BeansException e) {
            e.printStackTrace();
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "保存失败!");
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
